package com.seven.first.mapper;

import com.seven.first.dao.base.SevenBaseMapper;
import com.seven.first.po.ExampleUserInfoPO;
import com.seven.first.query.ExampleUserInfoQueryDTO;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface ExampleUserInfoMapper extends  SevenBaseMapper<ExampleUserInfoPO, ExampleUserInfoQueryDTO> {


    @Override
    @Results(id = "allColumnResult", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "userName", column = "user_name"),
            @Result(property = "password", column = "password"),
            @Result(property = "nickName", column = "nick_name"),
            @Result(property = "email", column = "email"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "address", column = "address"),
            @Result(property = "createdTime", column = "created_time")
    })
    @Select("<script>" +
                    "select t.id, t.user_name, t.nick_name, t.email, t.phone, t.address, t.created_time,t.password" +
                    "    from user_info t" +
                    "<where>" +
                    "   <if test='userName != null and userName != &quot;&quot; '>" +
                    "       and t.user_name like CONCAT('%', #{userName}, '%')" +
                    "   </if>" +
                    "   <if test='id != null and id != &quot;&quot; '>" +
                    "       and t.id = #{id}" +
                    "   </if>" +
                    "   <if test='password != null and password != &quot;&quot; '>" +
                    "       and t.app_type = #{password}" +
                    "   </if>" +
                    "   <if test='nickName != null and nickName != &quot;&quot; '>" +
                    "       and t.nick_name like CONCAT('%', #{nickName}, '%')" +
                    "   </if>" +
                    "   <if test='email != null and email != &quot;&quot; '>" +
                    "       and t.email like CONCAT('%', #{email}, '%')" +
                    "   </if>" +
                    "   <if test='phone != null and phone != &quot;&quot; '>" +
                    "       and t.phone like CONCAT('%', #{phone}, '%')" +
                    "   </if>" +
                    "   <if test='address != null and address != &quot;&quot; '>" +
                    "       and t.address like CONCAT('%', #{address}, '%')" +
                    "   </if>" +
                    "   <if test='ids != null and ids.size > 0 '>" +
                    "     and t.id in " +
                    "           <foreach collection='ids' index='index' item='item' open='(' separator=',' close=')' > "+
                    "               #{item}" +
                    "            </foreach>  " +
                    "   </if>" +
                    "   <if test='startTime != null and startTime != &quot;&quot; and endTime != null and endTime != &quot;&quot;'>" +
                    "       and t.created_time between str_to_date(#{startTime},'%Y-%m-%d %H:%i:%s') and str_to_date(#{endTime},'%Y-%m-%d %H:%i:%s')" +
                    "   </if>" +
                    "</where>" +
                    "   order by t.created_time desc" +
                    "</script>")
    List<ExampleUserInfoPO> listByQuery(ExampleUserInfoQueryDTO exampleUserInfoQueryDTO);


}
